package com.qeebu.SMSManagerClient.base;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;

/**
 * 所有的activity都继承该activity
 * 便于对所有的activity进行统一管理，如退出等
 * @author yongjun
 *
 */
public class BaseActivity extends Activity
{
    private static boolean ALLOW_STRICT_MODE = false;
    
    /*对所有的activity保持一个弱引用，即不至于阻止垃圾收集收集该无用activity,同时又能对该activity进行操作*/
    private static List<WeakReference<Activity>> actList = new ArrayList<WeakReference<Activity>>();
    
    protected void onCreate(Bundle savedInstanceState){
        if(ALLOW_STRICT_MODE && Build.VERSION.SDK_INT > 9){
            StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() //构造StrictMode  
            
                .detectDiskReads() //当发生磁盘读操作时输出  

                .detectDiskWrites()//当发生磁盘写操作时输出  

                .detectNetwork()  //访问网络时输出，这里可以替换为detectAll() 就包括了磁盘读写和网络I/O  

                .penaltyLog()  //以日志的方式输出  

                .build());  

            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()  

            .detectLeakedSqlLiteObjects()

            .penaltyLog() //以日志的方式输出  

            .penaltyDeath()  

            .build());
        }
        super.onCreate(savedInstanceState);
        actList.add(new WeakReference<Activity>(this));
    }
    
    public static void stopAllActivity(){
        int len = actList.size();
        for(int i=0; i<len; i++){
            Activity act = actList.get(i).get();
            if(act != null){
                act.finish();
            }
        }
    }

}
